package com.android.BluethootChess.rules;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Point;

import com.android.BluethootChess.model.GameBoardMatrix;
import com.android.BluethootChess.model.PieceColor;

/**
 * KingRules clasa care implementeaza interfata PieceRulesInterface si defineste
 * regulile pentru piesa rege.
 * 
 * @see PieceRule
 */
public class KingRules extends PieceRule {

	public KingRules(GameBoardMatrix gameMatrix, PieceColor color) {
		super(gameMatrix, color);
	}


	// TODO codul asta poate fi refactorizat.
	public List<Point> findAllAvaiblePositions() {
		List<Point> list = new ArrayList<Point>();

		int pieceLine = piecePosition.x;
		int pieceCol = piecePosition.y;

		if (isValidLocation(pieceLine + 1, pieceCol)) {
			list.add(new Point(pieceLine + 1, pieceCol));
		}

		if (isValidLocation(pieceLine + 1, pieceCol + 1)) {
			list.add(new Point(pieceLine + 1, pieceCol + 1));
		}

		if (isValidLocation(pieceLine + 1, pieceCol - 1)) {
			list.add(new Point(pieceLine + 1, pieceCol - 1));
		}

		if (isValidLocation(pieceLine - 1, pieceCol)) {
			list.add(new Point(pieceLine - 1, pieceCol));
		}
		if (isValidLocation(pieceLine - 1, pieceCol - 1)) {
			list.add(new Point(pieceLine - 1, pieceCol - 1));
		}

		if (isValidLocation(pieceLine - 1, pieceCol + 1)) {
			list.add(new Point(pieceLine - 1, pieceCol + 1));
		}

		if (isValidLocation(pieceLine, pieceCol + 1)) {
			list.add(new Point(pieceLine, pieceCol + 1));
		}

		if (isValidLocation(pieceLine, pieceCol - 1)) {
			list.add(new Point(pieceLine, pieceCol - 1));
		}

		return list;
	}
}